﻿namespace eProject.ViewModel.Commands
{
    public class DeleteScheduleItemCommand : ICommand
    {
        private readonly CommonManager _manager;
        private int _index;

        private readonly ScheduleItemViewModel _item;

        private bool _isCanceled;
        private bool _isExecuted;

        public DeleteScheduleItemCommand(CommonManager manager, ScheduleItemViewModel scheduleItem)
        {
            _manager = manager;
            _item = scheduleItem;
            
        }

        public void Execute()
        {
            if (_isExecuted) return;
            
            _index = _manager.ScheduleItems.IndexOf(_item);
            _manager.DeleteScheduleItem(_item);
                       
            _isExecuted = true;
            _isCanceled = false;
        }

        public void Unexecute()
        {
            if (_isCanceled) return;
            _manager.AddScheduleItem(_item,_index); 
            _isCanceled = true;
            _isExecuted = false;
        }
    }
}
